home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / readline-2.0mg.tar.gz / readline-2.0mg.tar / readline-2.0mg / rltty.c < prev    next >
C/C++ Source or Header  |  1994-11-20  |  16KB  |  702 lines

  1. /* rltty.c -- functions to prepare and restore the terminal for readline's
  2.    use. */
  3.  
  4. /* Copyright (C) 1992 Free Software Foundation, Inc.
  5.  
  6.    This file is part of the GNU Readline Library, a library for
  7.    reading lines of text with interactive input and history editing.
  8.  
  9.    The GNU Readline Library is free software; you can redistribute it
  10.    and/or modify it under the terms of the GNU General Public License
  11.    as published by the Free Software Foundation; either version 1, or
  12.    (at your option) any later version.
  13.  
  14.    The GNU Readline Library is distributed in the hope that it will be
  15.    useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  16.    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.    GNU General Public License for more details.
  18.  
  19.    The GNU General Public License is often shipped with GNU software, and
  20.    is generally kept in a file called COPYING or LICENSE.  If you do not
  21.    have a copy of the license, write to the Free Software Foundation,
  22.    675 Mass Ave, Cambridge, MA 02139, USA. */
  23. #define READLINE_LIBRARY
  24.  
  25. #if defined (HAVE_CONFIG_H)
  26. #  include "config.h"
  27. #endif
  28.  
  29. #include <sys/types.h>
  30. #include <signal.h>
  31. #include <errno.h>
  32. #include <stdio.h>
  33.  
  34. #if defined (HAVE_UNISTD_H)
  35. #  include <unistd.h>
  36. #endif /* HAVE_UNISTD_H */
  37.  
  38. #include "rldefs.h"
  39. #include "readline.h"
  40.  
  41. #if !defined (errno)
  42. extern int errno;
  43. #endif /* !errno */
  44.  
  45. extern int readline_echoing_p;
  46. extern int _rl_eof_char;
  47.  
  48. #if defined (__GO32__)
  49. #  include <sys/pc.h>
  50. #  undef HANDLE_SIGNALS
  51. #endif /* __GO32__ */
  52.  
  53. static int output_was_flushed;
  54.  
  55. /* **************************************************************** */
  56. /*                                    */
  57. /*               Signal Management                */
  58. /*                                    */
  59. /* **************************************************************** */
  60.  
  61. #if defined (HAVE_POSIX_SIGNALS)
  62. static sigset_t sigint_set, sigint_oset;
  63. #else /* !HAVE_POSIX_SIGNALS */
  64. #  if defined (HAVE_BSD_SIGNALS)
  65. static int sigint_oldmask;
  66. #  endif /* HAVE_BSD_SIGNALS */
  67. #endif /* !HAVE_POSIX_SIGNALS */
  68.  
  69. static int sigint_blocked = 0;
  70.  
  71. /* Cause SIGINT to not be delivered until the corresponding call to
  72.    release_sigint(). */
  73. static void
  74. block_sigint ()
  75. {
  76.   if (sigint_blocked)
  77.     return;
  78.  
  79. #if defined (HAVE_POSIX_SIGNALS)
  80.   sigemptyset (&sigint_set);
  81.   sigemptyset (&sigint_oset);
  82.   sigaddset (&sigint_set, SIGINT);
  83.   sigprocmask (SIG_BLOCK, &sigint_set, &sigint_oset);
  84. #else /* !HAVE_POSIX_SIGNALS */
  85. #  if defined (HAVE_BSD_SIGNALS)
  86.   sigint_oldmask = sigblock (sigmask (SIGINT));
  87. #  else /* !HAVE_BSD_SIGNALS */
  88. #    if defined (HAVE_USG_SIGHOLD)
  89.   sighold (SIGINT);
  90. #    endif /* HAVE_USG_SIGHOLD */
  91. #  endif /* !HAVE_BSD_SIGNALS */
  92. #endif /* !HAVE_POSIX_SIGNALS */
  93.   sigint_blocked = 1;
  94. }
  95.  
  96. /* Allow SIGINT to be delivered. */
  97. static void
  98. release_sigint ()
  99. {
  100.   if (!sigint_blocked)
  101.     return;
  102.  
  103. #if defined (HAVE_POSIX_SIGNALS)
  104.   sigprocmask (SIG_SETMASK, &sigint_oset, (sigset_t *)NULL);
  105. #else
  106. #  if defined (HAVE_BSD_SIGNALS)
  107.   sigsetmask (sigint_oldmask);
  108. #  else /* !HAVE_BSD_SIGNALS */
  109. #    if defined (HAVE_USG_SIGHOLD)
  110.   sigrelse (SIGINT);
  111. #    endif /* HAVE_USG_SIGHOLD */
  112. #  endif /* !HAVE_BSD_SIGNALS */
  113. #endif /* !HAVE_POSIX_SIGNALS */
  114.  
  115.   sigint_blocked = 0;
  116. }
  117.  
  118. /* **************************************************************** */
  119. /*                                    */
  120. /*         Controlling the Meta Key and Keypad            */
  121. /*                                    */
  122. /* **************************************************************** */
  123.  
  124. extern int term_has_meta;
  125. extern char *term_mm;
  126. extern char *term_mo;
  127.  
  128. extern char *term_ks;
  129. extern char *term_ke;
  130.  
  131. static int
  132. outchar (c)
  133.      int c;
  134. {
  135.   return putc (c, rl_outstream);
  136. }
  137.  
  138. /* Turn on/off the meta key depending on ON. */
  139. static void
  140. control_meta_key (on)
  141.      int on;
  142. {
  143.   if (term_has_meta)
  144.     {
  145.       if (on && term_mm)
  146.     tputs (term_mm, 1, outchar);
  147.       else if (!on && term_mo)
  148.     tputs (term_mo, 1, outchar);
  149.     }
  150. }
  151.  
  152. static void
  153. control_keypad (on)
  154.      int on;
  155. {
  156.   if (on && term_ks)
  157.     tputs (term_ks, 1, outchar);
  158.   else if (!on && term_ke)
  159.     tputs (term_ke, 1, outchar);
  160. }
  161.  
  162. /* **************************************************************** */
  163. /*                                    */
  164. /*              Saving and Restoring the TTY                */
  165. /*                                    */
  166. /* **************************************************************** */
  167.  
  168. /* Non-zero means that the terminal is in a prepped state. */
  169. static int terminal_prepped = 0;
  170.  
  171. /* If non-zero, means that this process has called tcflow(fd, TCOOFF)
  172.    and output is suspended. */
  173. #if defined (__ksr1__)
  174. static int ksrflow = 0;
  175. #endif
  176. #if defined (NEW_TTY_DRIVER)
  177.  
  178. /* Values for the `flags' field of a struct bsdtty.  This tells which
  179.    elements of the struct bsdtty have been fetched from the system and
  180.    are valid. */
  181. #define SGTTY_SET    0x01
  182. #define LFLAG_SET    0x02
  183. #define TCHARS_SET    0x04
  184. #define LTCHARS_SET    0x08
  185.  
  186. struct bsdtty {
  187.   struct sgttyb sgttyb;    /* Basic BSD tty driver information. */
  188.   int lflag;        /* Local mode flags, like LPASS8. */
  189. #if defined (TIOCGETC)
  190.   struct tchars tchars;    /* Terminal special characters, including ^S and ^Q. */
  191. #endif
  192. #if defined (TIOCGLTC)
  193.   struct ltchars ltchars; /* 4.2 BSD editing characters */
  194. #endif
  195.   int flags;        /* Bitmap saying which parts of the struct are valid. */
  196. };
  197.  
  198. #define TIOTYPE struct bsdtty
  199.  
  200. static TIOTYPE otio;
  201.  
  202. static int
  203. get_tty_settings (tty, tiop)
  204.      int tty;
  205.      TIOTYPE *tiop;
  206. {
  207. #if !defined (SHELL) && defined (TIOCGWINSZ)
  208.   struct winsize w;
  209.  
  210.   if (ioctl (tty, TIOCGWINSZ, &w) == 0)
  211.       (void) ioctl (tty, TIOCSWINSZ, &w);
  212. #endif
  213.  
  214.   tiop->flags = tiop->lflag = 0;
  215.  
  216.   ioctl (tty, TIOCGETP, &(tiop->sgttyb));
  217.   tiop->flags |= SGTTY_SET;
  218.  
  219. #if defined (TIOCLGET)
  220.   ioctl (tty, TIOCLGET, &(tiop->lflag));
  221.   tiop->flags |= LFLAG_SET;
  222. #endif
  223.  
  224. #if defined (TIOCGETC)
  225.   ioctl (tty, TIOCGETC, &(tiop->tchars));
  226.   tiop->flags |= TCHARS_SET;
  227. #endif
  228.  
  229. #if defined (TIOCGLTC)
  230.   ioctl (tty, TIOCGLTC, &(tiop->ltchars));
  231.   tiop->flags |= LTCHARS_SET;
  232. #endif
  233.  
  234.   return 0;
  235. }
  236.  
  237. set_tty_settings (tty, tiop)
  238.      int tty;
  239.      TIOTYPE *tiop;
  240. {
  241.   if (tiop->flags & SGTTY_SET)
  242.     {
  243.       ioctl (tty, TIOCSETN, &(tiop->sgttyb));
  244.       tiop->flags &= ~SGTTY_SET;
  245.     }
  246.   readline_echoing_p = 1;
  247.  
  248. #if defined (TIOCLSET)
  249.   if (tiop->flags & LFLAG_SET)
  250.     {
  251.       ioctl (tty, TIOCLSET, &(tiop->lflag));
  252.       tiop->flags &= ~LFLAG_SET;
  253.     }
  254. #endif
  255.  
  256. #if defined (TIOCSETC)
  257.   if (tiop->flags & TCHARS_SET)
  258.     {
  259.       ioctl (tty, TIOCSETC, &(tiop->tchars));
  260.       tiop->flags &= ~TCHARS_SET;
  261.     }
  262. #endif
  263.  
  264. #if defined (TIOCSLTC)
  265.   if (tiop->flags & LTCHARS_SET)
  266.     {
  267.       ioctl (tty, TIOCSLTC, &(tiop->ltchars));
  268.       tiop->flags &= ~LTCHARS_SET;
  269.     }
  270. #endif
  271.  
  272.   return 0;
  273. }
  274.  
  275. static void
  276. prepare_terminal_settings (meta_flag, otio, tiop)
  277.      int meta_flag;
  278.      TIOTYPE otio, *tiop;
  279. {
  280. #if !defined (__GO32__)
  281.   readline_echoing_p = (otio.sgttyb.sg_flags & ECHO);
  282.  
  283.   /* Copy the original settings to the structure we're going to use for
  284.      our settings. */
  285.   tiop->sgttyb = otio.sgttyb;
  286.   tiop->lflag = otio.lflag;
  287. #if defined (TIOCGETC)
  288.   tiop->tchars = otio.tchars;
  289. #endif
  290. #if defined (TIOCGLTC)
  291.   tiop->ltchars = otio.ltchars;
  292. #endif
  293.   tiop->flags = otio.flags;
  294.  
  295.   /* First, the basic settings to put us into character-at-a-time, no-echo
  296.      input mode. */
  297.   tiop->sgttyb.sg_flags &= ~(ECHO | CRMOD);
  298.   tiop->sgttyb.sg_flags |= CBREAK;
  299.  
  300.   /* If this terminal doesn't care how the 8th bit is used, then we can
  301.      use it for the meta-key.  If only one of even or odd parity is
  302.      specified, then the terminal is using parity, and we cannot. */
  303. #if !defined (ANYP)
  304. #  define ANYP (EVENP | ODDP)
  305. #endif
  306.   if (((otio.sgttyb.sg_flags & ANYP) == ANYP) ||
  307.       ((otio.sgttyb.sg_flags & ANYP) == 0))
  308.     {
  309.       tiop->sgttyb.sg_flags |= ANYP;
  310.  
  311.       /* Hack on local mode flags if we can. */
  312. #if defined (TIOCLGET)
  313. #  if defined (LPASS8)
  314.       tiop->lflag |= LPASS8;
  315. #  endif /* LPASS8 */
  316. #endif /* TIOCLGET */
  317.     }
  318.  
  319. #if defined (TIOCGETC)
  320. #  if defined (USE_XON_XOFF)
  321.   /* Get rid of terminal output start and stop characters. */
  322.   tiop->tchars.t_stopc = -1; /* C-s */
  323.   tiop->tchars.t_startc = -1; /* C-q */
  324.  
  325.   /* If there is an XON character, bind it to restart the output. */
  326.   if (otio.tchars.t_startc != -1)
  327.     rl_bind_key (otio.tchars.t_startc, rl_restart_output);
  328. #  endif /* USE_XON_XOFF */
  329.  
  330.   /* If there is an EOF char, bind _rl_eof_char to it. */
  331.   if (otio.tchars.t_eofc != -1)
  332.     _rl_eof_char = otio.tchars.t_eofc;
  333.  
  334. #  if defined (NO_KILL_INTR)
  335.   /* Get rid of terminal-generated SIGQUIT and SIGINT. */
  336.   tiop->tchars.t_quitc = -1; /* C-\ */
  337.   tiop->tchars.t_intrc = -1; /* C-c */
  338. #  endif /* NO_KILL_INTR */
  339. #endif /* TIOCGETC */
  340.  
  341. #if defined (TIOCGLTC)
  342.   /* Make the interrupt keys go away.  Just enough to make people happy. */
  343.   tiop->ltchars.t_dsuspc = -1;    /* C-y */
  344.   tiop->ltchars.t_lnextc = -1;    /* C-v */
  345. #endif /* TIOCGLTC */
  346. #endif /* !__GO32__ */
  347. }
  348.  
  349. #else  /* !defined (NEW_TTY_DRIVER) */
  350.  
  351. #if !defined (VMIN)
  352. #  define VMIN VEOF
  353. #endif
  354.  
  355. #if !defined (VTIME)
  356. #  define VTIME VEOL
  357. #endif
  358.  
  359. #if defined (TERMIOS_TTY_DRIVER)
  360. #  define TIOTYPE struct termios
  361. #  define DRAIN_OUTPUT(fd)    tcdrain (fd)
  362. #  define GETATTR(tty, tiop)    (tcgetattr (tty, tiop))
  363. #  define SETATTR(tty, tiop)    (tcsetattr (tty, TCSANOW, tiop))
  364. #else
  365. #  define TIOTYPE struct termio
  366. #  define DRAIN_OUTPUT(fd)
  367. #  define GETATTR(tty, tiop)    (ioctl (tty, TCGETA, tiop))
  368. #  define SETATTR(tty, tiop)    (ioctl (tty, TCSETA, tiop))
  369. #endif /* !TERMIOS_TTY_DRIVER */
  370.  
  371. static TIOTYPE otio;
  372.  
  373. #if defined (FLUSHO)
  374. #  define OUTPUT_BEING_FLUSHED(tp)  (tp->c_lflag & FLUSHO)
  375. #else
  376. #  define OUTPUT_BEING_FLUSHED(tp)  0
  377. #endif
  378.  
  379. static int
  380. get_tty_settings (tty, tiop)
  381.      int tty;
  382.      TIOTYPE *tiop;
  383. {
  384. #if !defined (SHELL) && defined (TIOCGWINSZ)
  385.   struct winsize w;
  386.  
  387.   if (ioctl (tty, TIOCGWINSZ, &w) == 0)
  388.       (void) ioctl (tty, TIOCSWINSZ, &w);
  389. #endif
  390.  
  391.   /* Keep looping if output is being flushed after a ^O (or whatever
  392.      the flush character is). */
  393.   while (GETATTR (tty, tiop) < 0 || OUTPUT_BEING_FLUSHED (tiop))
  394.     {
  395.       if (OUTPUT_BEING_FLUSHED (tiop))
  396.         continue;
  397.       if (errno != EINTR)
  398.     return -1;
  399.       errno = 0;
  400.     }
  401.   return 0;
  402. }
  403.  
  404. static int
  405. set_tty_settings (tty, tiop)
  406.      int tty;
  407.      TIOTYPE *tiop;
  408. {
  409.   while (SETATTR (tty, tiop) < 0)
  410.     {
  411.       if (errno != EINTR)
  412.     return -1;
  413.       errno = 0;
  414.     }
  415.  
  416. #if 0
  417.  
  418. #if defined (TERMIOS_TTY_DRIVER)
  419. #  if defined (__ksr1__)
  420.   if (ksrflow)
  421.     {
  422.       ksrflow = 0;
  423.       tcflow (tty, TCOON);
  424.     }
  425. #  else /* !ksr1 */
  426.   tcflow (tty, TCOON);        /* Simulate a ^Q. */
  427. #  endif /* !ksr1 */
  428. #else
  429.   ioctl (tty, TCXONC, 1);    /* Simulate a ^Q. */
  430. #endif /* !TERMIOS_TTY_DRIVER */
  431.  
  432. #endif
  433.  
  434.   return 0;
  435. }
  436.  
  437. static void
  438. prepare_terminal_settings (meta_flag, otio, tiop)
  439.      int meta_flag;
  440.      TIOTYPE otio, *tiop;
  441. {
  442.   readline_echoing_p = (otio.c_lflag & ECHO);
  443.  
  444.   tiop->c_lflag &= ~(ICANON | ECHO);
  445.  
  446.   if ((unsigned char) otio.c_cc[VEOF] != (unsigned char) _POSIX_VDISABLE)
  447.     _rl_eof_char = otio.c_cc[VEOF];
  448.  
  449. #if defined (USE_XON_XOFF)
  450. #if defined (IXANY)
  451.   tiop->c_iflag &= ~(IXON | IXOFF | IXANY);
  452. #else
  453.   /* `strict' Posix systems do not define IXANY. */
  454.   tiop->c_iflag &= ~(IXON | IXOFF);
  455. #endif /* IXANY */
  456. #endif /* USE_XON_XOFF */
  457.  
  458.   /* Only turn this off if we are using all 8 bits. */
  459.   if (((tiop->c_cflag & CSIZE) == CS8) || meta_flag)
  460.     tiop->c_iflag &= ~(ISTRIP | INPCK);
  461.  
  462.   /* Make sure we differentiate between CR and NL on input. */
  463.   tiop->c_iflag &= ~(ICRNL | INLCR);
  464.  
  465. #if !defined (HANDLE_SIGNALS)
  466.   tiop->c_lflag &= ~ISIG;
  467. #else
  468.   tiop->c_lflag |= ISIG;
  469. #endif
  470.  
  471.   tiop->c_cc[VMIN] = 1;
  472.   tiop->c_cc[VTIME] = 0;
  473.  
  474.   if (tiop->c_lflag & FLUSHO)
  475.     {
  476.       output_was_flushed = 1;
  477.       tiop->c_lflag &= ~FLUSHO;
  478.       otio.c_lflag &= ~FLUSHO;
  479.     }
  480.  
  481.   /* Turn off characters that we need on Posix systems with job control,
  482.      just to be sure.  This includes ^Y and ^V.  This should not really
  483.      be necessary.  */
  484. #if defined (TERMIOS_TTY_DRIVER) && defined (_POSIX_VDISABLE)
  485.  
  486. #if defined (VLNEXT)
  487.   tiop->c_cc[VLNEXT] = _POSIX_VDISABLE;
  488. #endif
  489.  
  490. #if defined (VDSUSP)
  491.   tiop->c_cc[VDSUSP] = _POSIX_VDISABLE;
  492. #endif
  493.  
  494. #endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */
  495. }
  496. #endif  /* NEW_TTY_DRIVER */
  497.  
  498. /* Put the terminal in CBREAK mode so that we can detect key presses. */
  499. void
  500. rl_prep_terminal (meta_flag)
  501.      int meta_flag;
  502. {
  503. #if !defined (__GO32__)
  504.   int tty = fileno (rl_instream);
  505.   TIOTYPE tio;
  506.  
  507.   if (terminal_prepped)
  508.     return;
  509.  
  510.   /* Try to keep this function from being INTerrupted. */
  511.   block_sigint ();
  512.  
  513.   if (get_tty_settings (tty, &tio) < 0)
  514.     {
  515.       release_sigint ();
  516.       return;
  517.     }
  518.  
  519.   otio = tio;
  520.  
  521.   prepare_terminal_settings (meta_flag, otio, &tio);
  522.  
  523.   if (set_tty_settings (tty, &tio) < 0)
  524.     {
  525.       release_sigint ();
  526.       return;
  527.     }
  528.  
  529.   if (output_was_flushed)
  530.     output_was_flushed = 0;
  531.  
  532.   control_meta_key (1);
  533.   control_keypad (1);
  534.   fflush (rl_outstream);
  535.   terminal_prepped = 1;
  536.  
  537.   release_sigint ();
  538. #endif /* !__GO32__ */
  539. }
  540.  
  541. /* Restore the terminal's normal settings and modes. */
  542. void
  543. rl_deprep_terminal ()
  544. {
  545. #if !defined (__GO32__)
  546.   int tty = fileno (rl_instream);
  547.  
  548.   if (!terminal_prepped)
  549.     return;
  550.  
  551.   /* Try to keep this function from being INTerrupted. */
  552.   block_sigint ();
  553.  
  554.   if (set_tty_settings (tty, &otio) < 0)
  555.     {
  556.       release_sigint ();
  557.       return;
  558.     }
  559.  
  560.   control_meta_key (0);
  561.   control_keypad (0);
  562.   fflush (rl_outstream);
  563.   terminal_prepped = 0;
  564.  
  565.   release_sigint ();
  566. #endif /* !__GO32__ */
  567. }
  568.  
  569. /* **************************************************************** */
  570. /*                                    */
  571. /*            Bogus Flow Control                  */
  572. /*                                    */
  573. /* **************************************************************** */
  574.  
  575. rl_restart_output (count, key)
  576.      int count, key;
  577. {
  578.   int fildes = fileno (rl_outstream);
  579. #if defined (TIOCSTART)
  580. #if defined (apollo)
  581.   ioctl (&fildes, TIOCSTART, 0);
  582. #else
  583.   ioctl (fildes, TIOCSTART, 0);
  584. #endif /* apollo */
  585.  
  586. #else /* !TIOCSTART */
  587. #  if defined (TERMIOS_TTY_DRIVER)
  588. #    if defined (__ksr1__)
  589.   if (ksrflow)
  590.     {
  591.       ksrflow = 0;
  592.       tcflow (fildes, TCOON);
  593.     }
  594. #    else /* !ksr1 */
  595.   tcflow (fildes, TCOON);        /* Simulate a ^Q. */
  596. #    endif /* !ksr1 */
  597. #  else /* !TERMIOS_TTY_DRIVER */
  598. #    if defined (TCXONC)
  599.   ioctl (fildes, TCXONC, TCOON);
  600. #    endif /* TCXONC */
  601. #  endif /* !TERMIOS_TTY_DRIVER */
  602. #endif /* !TIOCSTART */
  603.  
  604.   return 0;
  605. }
  606.  
  607. rl_stop_output (count, key)
  608.      int count, key;
  609. {
  610.   int fildes = fileno (rl_instream);
  611.  
  612. #if defined (TIOCSTOP)
  613. # if defined (apollo)
  614.   ioctl (&fildes, TIOCSTOP, 0);
  615. # else
  616.   ioctl (fildes, TIOCSTOP, 0);
  617. # endif /* apollo */
  618. #else /* !TIOCSTOP */
  619. # if defined (TERMIOS_TTY_DRIVER)
  620. #  if defined (__ksr1__)
  621.   ksrflow = 1;
  622. #  endif /* ksr1 */
  623.   tcflow (fildes, TCOOFF);
  624. # else
  625. #   if defined (TCXONC)
  626.   ioctl (fildes, TCXONC, TCOON);
  627. #   endif /* TCXONC */
  628. # endif /* !TERMIOS_TTY_DRIVER */
  629. #endif /* !TIOCSTOP */
  630.  
  631.   return 0;
  632. }
  633.  
  634. /* **************************************************************** */
  635. /*                                    */
  636. /*            Default Key Bindings                */
  637. /*                                    */
  638. /* **************************************************************** */
  639. void
  640. rltty_set_default_bindings (kmap)
  641.      Keymap kmap;
  642. {
  643.   TIOTYPE ttybuff;
  644.   int tty = fileno (rl_instream);
  645.  
  646. #if defined (NEW_TTY_DRIVER)
  647.  
  648. #define SET_SPECIAL(sc, func) \
  649.   do \
  650.     { \
  651.       int ic; \
  652.       ic = sc; \
  653.       if (ic != -1 && kmap[ic].type == ISFUNC) \
  654.     kmap[ic].function = func; \
  655.     } \
  656.   while (0)
  657.  
  658.   if (get_tty_settings (tty, &ttybuff) == 0)
  659.     {
  660.       if (ttybuff.flags & SGTTY_SET)
  661.     {
  662.       SET_SPECIAL (ttybuff.sgttyb.sg_erase, rl_rubout);
  663.       SET_SPECIAL (ttybuff.sgttyb.sg_kill, rl_unix_line_discard);
  664.     }
  665.  
  666. #  if defined (TIOCGLTC)
  667.       if (ttybuff.flags & LTCHARS_SET)
  668.     {
  669.       SET_SPECIAL (ttybuff.ltchars.t_werasc, rl_unix_word_rubout);
  670.       SET_SPECIAL (ttybuff.ltchars.t_lnextc, rl_quoted_insert);
  671.     }
  672. #  endif /* TIOCGLTC */
  673.     }
  674.  
  675. #else /* !NEW_TTY_DRIVER */
  676.  
  677. #define SET_SPECIAL(sc, func) \
  678.   do \
  679.     { \
  680.       unsigned char uc; \
  681.       uc = ttybuff.c_cc[sc]; \
  682.       if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \
  683.     kmap[uc].function = func; \
  684.     } \
  685.   while (0)
  686.  
  687.   if (get_tty_settings (tty, &ttybuff) == 0)
  688.     {
  689.       SET_SPECIAL (VERASE, rl_rubout);
  690.       SET_SPECIAL (VKILL, rl_unix_line_discard);
  691.  
  692. #  if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER)
  693.       SET_SPECIAL (VLNEXT, rl_quoted_insert);
  694. #  endif /* VLNEXT && TERMIOS_TTY_DRIVER */
  695.  
  696. #  if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER)
  697.       SET_SPECIAL (VWERASE, rl_unix_word_rubout);
  698. #  endif /* VWERASE && TERMIOS_TTY_DRIVER */
  699.     }
  700. #endif /* !NEW_TTY_DRIVER */
  701. }
  702.